<template>
  <div>
    <!-- 搜索 -->
    <!-- 考核单 -- 车厂-->
    <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" @click="saveDialog">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>

    <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <selectDelearPage @close="Delearclose" @save="Delearsave"></selectDelearPage>
    </BaseDialog>
  </div>
</template>
<script>
  import { exportExcelFile } from '@/utils/index';
  import { getListByPage,downloadModel,getListForExport } from '@/api/claim/dealer/CheckSheetQueryDealer';
  import { getPartType } from '@/api/claim/dealer/ClaimStatementMaintain/index';
  export default {
    props: ['rowData'],
    components: {
    },
    data() {
      return {
        dataList: [],
        // carType: {},
        visible: false,
        selectDelearFlag: false,
        visibleDrawer: false,
        collapse: false,
        infoId: null,
        topFilterInit: this.topFilterInitFun(),
        flterValue: {}, //参数
        fetchapi: getListByPage,
        columns: this.creatHeader(),


        fetchParams: {  assessClassify: this.rowData.carType, assessStatus:55451004,statusForFlag:3}, //ipa 接口
        selectedRows: [], //选中经销商
        dialogTitle: '选择车辆',
        visibleAdd: false
      };
    },
    created() {
      this.chuqi();
      // this.chuqi1();
      // this.chuqi2();
    },
    methods: {
      //保存
      saveDialog() {
        this.$emit('save', this.selectedRows);
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },

      // 导出
      exportFileBtn() {
        getListForExport(this.fetchParams).then(res => {
          exportExcelFile(res, '考核单');
        });
      },

      //考核类型
      async chuqi() {
        const res = await getPartType({ type: 5541 });
        if (res.resultCode == 200) {
          this.topFilterInit.find(x => x.fieldName == 'assessType').initialValue = '';
          this.topFilterInit.find(x => x.fieldName == 'assessType').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        }
      },
      //考核单状态
      async chuqi1() {
        const res = await getPartType({ type: 5545 });
        if (res.resultCode == 200) {
          this.topFilterInit.find(x => x.fieldName == 'assessStatus').initialValue = '';
          this.topFilterInit.find(x => x.fieldName == 'assessStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        }
      },
      //考核分类
      async chuqi2() {
        const res = await getPartType({ type: 5543 });
        if (res.resultCode == 200) {
          this.topFilterInit.find(x => x.fieldName == 'assessClassify').initialValue = '';
          this.topFilterInit.find(x => x.fieldName == 'assessClassify').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        }
      },
      //搜索数据
      topFilterInitFun() {
        return [
          { type: 'INPUT', label: '考核单号', fieldName: 'assessNo', placeholder: '请输入考核单号...', initialValue: '' },
          { type: 'SELECT', label: '考核类型', fieldName: 'assessType', placeholder: '请选择考核类型...', initialValue: '', itemList: [] },
          // { type: 'SELECT', label: '考核单状态', fieldName: 'assessStatus', placeholder: '请选择', initialValue: '', itemList: [] },
          {
            type: 'RANGE_DATE',
            label: '考核日期',
            fieldName: 'beginCreatedAt|endCreatedAt',
            placeholder: '请输入',
            initialValue: ''
          },
          // {
          //   type: 'INPUT',
          //   label: '经销商代码',
          //   fieldName: 'dealerCode',
          //   placeholder: '请输入',
          //   initialValue: '',
          //   unitRender: p => {
          //     return (
          //       <div>
          //       <multiuse-button icon="el-icon-search" onClick={() => this.SelectDelear()} />
          //     </div>
          //   );
          //   }
          // },
          // { type: 'INPUT', label: '经销商名称', fieldName: 'dealerName', placeholder: '请输入', initialValue: '' },
          // { type: 'SELECT', label: '考核分类', fieldName: 'assessClassify', placeholder: '请选择', initialValue: '', itemList: [] }
        ];
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = Object.assign({assessStatus:55451004,statusForFlag:3}, this.fetchParams, val,{assessClassify: this.rowData.carType});
        // this.SELECT();
      },
      //table表头和数据源
      creatHeader() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '考核单号', dataIndex: 'assessNo', sorter: true },
          { title: '考核类型', dataIndex: 'assessTypeStr', sorter: true },
          { title: '考核金额', dataIndex: 'assessAmount', sorter: true },
          { title: '考核原因', dataIndex: 'assessReason', sorter: true },
          { title: '考核日期', dataIndex: 'assessDate', sorter: true, dateFormat: 'yyyy-MM-dd' },
          { title: '考核人', dataIndex: 'assessBy', sorter: true },
          { title: '审核日期', dataIndex: 'checkAt', sorter: true, dateFormat: 'yyyy-MM-dd' },
          { title: '主键', dataIndex: 'assessId', sorter: true, hidden: true }
        ];
      },
      //选中
      selectChange(rows) {
        this.selectedRows = rows;
        console.log(this.selectedRows);
      },
      close() {
        this.visible = false;
        this.fetchParams = { ...this.fetchParams };
      },
      chooseOrderNo(val) {
        this.visible = true;
        this.rowData = val;
      },
      save(obj) {
        this.topFilterInit.find(x => x.fieldName == 'model').initialValue = obj[0].address;
        this.visible = false;
      },
      add() {
        this.visibleAdd = true;
      },
      closeAdd() {
        this.visibleAdd = false;
        this.fetchParams = { ...this.fetchParams };
      },
      saveAdd() {
        this.visibleAdd = false;
        this.fetchParams = { ...this.fetchParams };
      }, //经销商选择页面
      SelectDelear() {
        this.selectDelearFlag = true;
      }, //关闭
      Delearclose() {
        this.selectDelearFlag = false;
      },
      //保存
      Delearsave(obj) {
        this.topFilterInit.map(x => {
          if ('dealerCode' == x.fieldName) {
            x.initialValue = obj[0].dealerCode; //维修工单号返显
          }
        })

        this.selectDelearFlag = false;

      }
    }
    // mounted() {
    //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
    // }
  };
</script>

<style lang="less" scoped></style>
